package com.iss.okair.controller.assetstrans;

import com.iss.common.Message;
import com.iss.common.UuidTools;
import com.iss.okair.db.entity.AssetsNormal;
import com.iss.okair.db.entity.AssetsTranUse;
import com.iss.okair.db.entity.Assetstrans;
import com.iss.okair.service.trans.NormalTransService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RestController
@RequestMapping("logic/trans/normal")
public class NormalTransController {
    @Autowired
    private NormalTransService service;

    @RequestMapping("/checkin/list")
    public List<AssetsTranUse> find(AssetsTranUse trans) {
        return service.find(trans);
    }

    @RequestMapping("/checkout/list")
    public List<AssetsTranUse> findout(AssetsTranUse trans) {
        return service.findout(trans);
    }

    @RequestMapping("/instock")
    public Message add(Assetstrans trans) {
        Message msg = new Message();
        if (service.add(trans)) {
            msg.setError(false);
            msg.setMsg("入库成功");
        } else {
            msg.setError(true);
            msg.setMsg("入库失败");
        }
        return msg;
    }

    @RequestMapping("/history/{assetsid}")
    public List<AssetsTranUse> Record(@PathVariable String assetsid) {
        return service.Record(assetsid);
    }
    @RequestMapping("/{transtype}")
    public Message Use( @PathVariable("transtype") String transtype, Assetstrans finance){
        Message msg =new Message();
        finance.setId(UuidTools.buildUUID());
        if (service.Use(transtype,finance)){
            msg.setError(false);
            msg.setMsg("成功");
        }else {
            msg.setError(true);
            msg.setMsg("失败");
        }
        return  msg;
    }
}